
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/polys/solvers.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:28:05 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Poly solvers &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
    <script src="../../_static/jquery.js"></script>
    <script src="../../_static/underscore.js"></script>
    <script src="../../_static/doctools.js"></script>
    <script src="../../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../../live.sympy.org/static/live-sphinx.js"></script>
    <script async="async" src="../../../../cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest8331.js?config=TeX-AMS_HTML-full"></script>
    <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]]}})</script>
    
    <link rel="shortcut icon" href="../../_static/sympy-notailtext-favicon.ico"/>
    <link href="solvers.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="Introducing the domainmatrix of the poly module" href="domainmatrix.html" />
    <link rel="prev" title="Literature" href="literature.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="domainmatrix.html" title="Introducing the domainmatrix of the poly module"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="literature.html" title="Literature"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" accesskey="U">Polynomial Manipulation</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Poly solvers</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="poly-solvers">
<span id="poly-solvers-docs"></span><h1>Poly solvers<a class="headerlink" href="#poly-solvers" title="Permalink to this headline">¶</a></h1>
<p>This module provides functions for solving systems of linear equations that
are used internally in sympy.</p>
<span class="target" id="module-sympy.polys.solvers"></span><p>Low-level linear systems solver.</p>
<section id="solve-lin-sys">
<h2>solve_lin_sys<a class="headerlink" href="#solve-lin-sys" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.polys.solvers.solve_lin_sys">
<span class="sig-prename descclassname"><span class="pre">sympy.polys.solvers.</span></span><span class="sig-name descname"><span class="pre">solve_lin_sys</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">eqs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">ring</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">_raw</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/polys/solvers.py#L182-L296"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.polys.solvers.solve_lin_sys" title="Permalink to this definition">¶</a></dt>
<dd><p>Solve a system of linear equations from a PolynomialRing</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>eqs: list[PolyElement]</strong></p>
<blockquote>
<div><p>The linear equations to be solved as elements of a
PolynomialRing (assumed equal to zero).</p>
</div></blockquote>
<p><strong>ring: PolynomialRing</strong></p>
<blockquote>
<div><p>The polynomial ring from which eqs are drawn. The generators of this
ring are the unkowns to be solved for and the domain of the ring is
the domain of the coefficients of the system of equations.</p>
</div></blockquote>
<p><strong>_raw: bool</strong></p>
<blockquote>
<div><p>If <em>_raw</em> is False, the keys and values in the returned dictionary
will be of type Expr (and the unit of the field will be removed from
the keys) otherwise the low-level polys types will be returned, e.g.
PolyElement: PythonRational.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><code class="docutils literal notranslate"><span class="pre">None</span></code> if the system has no solution.</p>
<p>dict[Symbol, Expr] if _raw=False</p>
<p>dict[Symbol, DomainElement] if _raw=True.</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>Solves a system of linear equations given as PolyElement instances of a
PolynomialRing. The basic arithmetic is carried out using instance of
DomainElement which is more efficient than <a class="reference internal" href="../core.html#sympy.core.expr.Expr" title="sympy.core.expr.Expr"><code class="xref py py-class docutils literal notranslate"><span class="pre">Expr</span></code></a>
for the most common inputs.</p>
<p>While this is a public function it is intended primarily for internal use
so its interface is not necessarily convenient. Users are suggested to use
the <a class="reference internal" href="../solvers/solveset.html#sympy.solvers.solveset.linsolve" title="sympy.solvers.solveset.linsolve"><code class="xref py py-func docutils literal notranslate"><span class="pre">sympy.solvers.solveset.linsolve()</span></code></a> function (which uses this
function internally) instead.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.polys.solvers</span> <span class="kn">import</span> <span class="n">solve_lin_sys</span><span class="p">,</span> <span class="n">sympy_eqs_to_ring</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x, y&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eqs</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span> <span class="o">-</span> <span class="n">y</span><span class="p">,</span> <span class="n">x</span> <span class="o">+</span> <span class="n">y</span> <span class="o">-</span> <span class="mi">2</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eqs_ring</span><span class="p">,</span> <span class="n">ring</span> <span class="o">=</span> <span class="n">sympy_eqs_to_ring</span><span class="p">(</span><span class="n">eqs</span><span class="p">,</span> <span class="p">[</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">solve_lin_sys</span><span class="p">(</span><span class="n">eqs_ring</span><span class="p">,</span> <span class="n">ring</span><span class="p">)</span>
<span class="go">{y: 1, x: 1}</span>
</pre></div>
</div>
<p>Passing <code class="docutils literal notranslate"><span class="pre">_raw=False</span></code> returns the same result except that the keys are
<code class="docutils literal notranslate"><span class="pre">Expr</span></code> rather than low-level poly types.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">solve_lin_sys</span><span class="p">(</span><span class="n">eqs_ring</span><span class="p">,</span> <span class="n">ring</span><span class="p">,</span> <span class="n">_raw</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">{x: 1, y: 1}</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="#sympy.polys.solvers.sympy_eqs_to_ring" title="sympy.polys.solvers.sympy_eqs_to_ring"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy_eqs_to_ring</span></code></a></dt><dd><p>prepares the inputs to <code class="docutils literal notranslate"><span class="pre">solve_lin_sys</span></code>.</p>
</dd>
<dt><a class="reference internal" href="../solvers/solveset.html#sympy.solvers.solveset.linsolve" title="sympy.solvers.solveset.linsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">linsolve</span></code></a></dt><dd><p><code class="docutils literal notranslate"><span class="pre">linsolve</span></code> uses <code class="docutils literal notranslate"><span class="pre">solve_lin_sys</span></code> internally.</p>
</dd>
<dt><a class="reference internal" href="../solvers/solvers.html#sympy.solvers.solvers.solve" title="sympy.solvers.solvers.solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.solvers.solvers.solve</span></code></a></dt><dd><p><code class="docutils literal notranslate"><span class="pre">solve</span></code> uses <code class="docutils literal notranslate"><span class="pre">solve_lin_sys</span></code> internally.</p>
</dd>
</dl>
</div>
</dd></dl>

</section>
<section id="eqs-to-matrix">
<h2>eqs_to_matrix<a class="headerlink" href="#eqs-to-matrix" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.polys.solvers.eqs_to_matrix">
<span class="sig-prename descclassname"><span class="pre">sympy.polys.solvers.</span></span><span class="sig-name descname"><span class="pre">eqs_to_matrix</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">eqs_coeffs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">eqs_rhs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">gens</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">domain</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/polys/solvers.py#L69-L124"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.polys.solvers.eqs_to_matrix" title="Permalink to this definition">¶</a></dt>
<dd><p>Get matrix from linear equations in dict format.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>eqs_coeffs: list[dict[Symbol, DomainElement]]</strong></p>
<blockquote>
<div><p>The left hand sides of the equations as dicts mapping from symbols to
coefficients where the coefficients are instances of
DomainElement.</p>
</div></blockquote>
<p><strong>eqs_rhs: list[DomainElements]</strong></p>
<blockquote>
<div><p>The right hand sides of the equations as instances of
DomainElement.</p>
</div></blockquote>
<p><strong>gens: list[Symbol]</strong></p>
<blockquote>
<div><p>The unknowns in the system of equations.</p>
</div></blockquote>
<p><strong>domain: Domain</strong></p>
<blockquote>
<div><p>The domain for coefficients of both lhs and rhs.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>The augmented matrix representation of the system as a DomainMatrix.</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>Get the matrix representation of a system of linear equations represented
as dicts with low-level DomainElement coefficients. This is an
<em>internal</em> function that is used by solve_lin_sys.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">ZZ</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.polys.solvers</span> <span class="kn">import</span> <span class="n">eqs_to_matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x, y&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eqs_coeff</span> <span class="o">=</span> <span class="p">[{</span><span class="n">x</span><span class="p">:</span><span class="n">ZZ</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="n">y</span><span class="p">:</span><span class="n">ZZ</span><span class="p">(</span><span class="mi">1</span><span class="p">)},</span> <span class="p">{</span><span class="n">x</span><span class="p">:</span><span class="n">ZZ</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="n">y</span><span class="p">:</span><span class="n">ZZ</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)}]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eqs_rhs</span> <span class="o">=</span> <span class="p">[</span><span class="n">ZZ</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="n">ZZ</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eqs_to_matrix</span><span class="p">(</span><span class="n">eqs_coeff</span><span class="p">,</span> <span class="n">eqs_rhs</span><span class="p">,</span> <span class="p">[</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">],</span> <span class="n">ZZ</span><span class="p">)</span>
<span class="go">DomainMatrix([[1, 1, 0], [1, -1, 1]], (2, 3), ZZ)</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="#sympy.polys.solvers.solve_lin_sys" title="sympy.polys.solvers.solve_lin_sys"><code class="xref py py-obj docutils literal notranslate"><span class="pre">solve_lin_sys</span></code></a></dt><dd><p>Uses <a class="reference internal" href="#sympy.polys.solvers.eqs_to_matrix" title="sympy.polys.solvers.eqs_to_matrix"><code class="xref py py-func docutils literal notranslate"><span class="pre">eqs_to_matrix()</span></code></a> internally</p>
</dd>
</dl>
</div>
</dd></dl>

</section>
<section id="sympy-eqs-to-ring">
<h2>sympy_eqs_to_ring<a class="headerlink" href="#sympy-eqs-to-ring" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.polys.solvers.sympy_eqs_to_ring">
<span class="sig-prename descclassname"><span class="pre">sympy.polys.solvers.</span></span><span class="sig-name descname"><span class="pre">sympy_eqs_to_ring</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">eqs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">symbols</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/polys/solvers.py#L127-L179"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.polys.solvers.sympy_eqs_to_ring" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert a system of equations from Expr to a PolyRing</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>eqs: List of Expr</strong></p>
<blockquote>
<div><p>A list of equations as Expr instances</p>
</div></blockquote>
<p><strong>symbols: List of Symbol</strong></p>
<blockquote>
<div><p>A list of the symbols that are the unknowns in the system of
equations.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Tuple[List[PolyElement], Ring]: The equations as PolyElement instances</p>
<p>and the ring of polynomials within which each equation is represented.</p>
</dd>
</dl>
<p class="rubric">Explanation</p>
<p>High-level functions like <code class="docutils literal notranslate"><span class="pre">solve</span></code> expect Expr as inputs but can use
<code class="docutils literal notranslate"><span class="pre">solve_lin_sys</span></code> internally. This function converts equations from
<code class="docutils literal notranslate"><span class="pre">Expr</span></code> to the low-level poly types used by the <code class="docutils literal notranslate"><span class="pre">solve_lin_sys</span></code>
function.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.polys.solvers</span> <span class="kn">import</span> <span class="n">sympy_eqs_to_ring</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;a, x, y&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eqs</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span><span class="o">-</span><span class="n">y</span><span class="p">,</span> <span class="n">x</span><span class="o">+</span><span class="n">a</span><span class="o">*</span><span class="n">y</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eqs_ring</span><span class="p">,</span> <span class="n">ring</span> <span class="o">=</span> <span class="n">sympy_eqs_to_ring</span><span class="p">(</span><span class="n">eqs</span><span class="p">,</span> <span class="p">[</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eqs_ring</span>
<span class="go">[x - y, x + a*y]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="n">eqs_ring</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="go">&lt;class &#39;sympy.polys.rings.PolyElement&#39;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ring</span>
<span class="go">ZZ(a)[x,y]</span>
</pre></div>
</div>
<p>With the equations in this form they can be passed to <code class="docutils literal notranslate"><span class="pre">solve_lin_sys</span></code>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.polys.solvers</span> <span class="kn">import</span> <span class="n">solve_lin_sys</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">solve_lin_sys</span><span class="p">(</span><span class="n">eqs_ring</span><span class="p">,</span> <span class="n">ring</span><span class="p">)</span>
<span class="go">{y: 0, x: 0}</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="id1">
<h2>_solve_lin_sys<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.polys.solvers._solve_lin_sys">
<span class="sig-prename descclassname"><span class="pre">sympy.polys.solvers.</span></span><span class="sig-name descname"><span class="pre">_solve_lin_sys</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">eqs_coeffs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">eqs_rhs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">ring</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/polys/solvers.py#L299-L357"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.polys.solvers._solve_lin_sys" title="Permalink to this definition">¶</a></dt>
<dd><p>Solve a linear system from dict of PolynomialRing coefficients</p>
<p class="rubric">Explanation</p>
<p>This is an <strong>internal</strong> function used by <a class="reference internal" href="#sympy.polys.solvers.solve_lin_sys" title="sympy.polys.solvers.solve_lin_sys"><code class="xref py py-func docutils literal notranslate"><span class="pre">solve_lin_sys()</span></code></a> after the
equations have been preprocessed. The role of this function is to split
the system into connected components and pass those to
<a class="reference internal" href="#sympy.polys.solvers._solve_lin_sys_component" title="sympy.polys.solvers._solve_lin_sys_component"><code class="xref py py-func docutils literal notranslate"><span class="pre">_solve_lin_sys_component()</span></code></a>.</p>
<p class="rubric">Examples</p>
<p>Setup a system for <span class="math notranslate nohighlight">\(x-y=0\)</span> and <span class="math notranslate nohighlight">\(x+y=2\)</span> and solve:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">sring</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.polys.solvers</span> <span class="kn">import</span> <span class="n">_solve_lin_sys</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x, y&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">R</span><span class="p">,</span> <span class="p">(</span><span class="n">xr</span><span class="p">,</span> <span class="n">yr</span><span class="p">)</span> <span class="o">=</span> <span class="n">sring</span><span class="p">([</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">],</span> <span class="p">[</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eqs</span> <span class="o">=</span> <span class="p">[{</span><span class="n">xr</span><span class="p">:</span><span class="n">R</span><span class="o">.</span><span class="n">one</span><span class="p">,</span> <span class="n">yr</span><span class="p">:</span><span class="o">-</span><span class="n">R</span><span class="o">.</span><span class="n">one</span><span class="p">},</span> <span class="p">{</span><span class="n">xr</span><span class="p">:</span><span class="n">R</span><span class="o">.</span><span class="n">one</span><span class="p">,</span> <span class="n">yr</span><span class="p">:</span><span class="n">R</span><span class="o">.</span><span class="n">one</span><span class="p">}]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eqs_rhs</span> <span class="o">=</span> <span class="p">[</span><span class="n">R</span><span class="o">.</span><span class="n">zero</span><span class="p">,</span> <span class="o">-</span><span class="mi">2</span><span class="o">*</span><span class="n">R</span><span class="o">.</span><span class="n">one</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_solve_lin_sys</span><span class="p">(</span><span class="n">eqs</span><span class="p">,</span> <span class="n">eqs_rhs</span><span class="p">,</span> <span class="n">R</span><span class="p">)</span>
<span class="go">{y: 1, x: 1}</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="#sympy.polys.solvers.solve_lin_sys" title="sympy.polys.solvers.solve_lin_sys"><code class="xref py py-obj docutils literal notranslate"><span class="pre">solve_lin_sys</span></code></a></dt><dd><p>This function is used internally by <a class="reference internal" href="#sympy.polys.solvers.solve_lin_sys" title="sympy.polys.solvers.solve_lin_sys"><code class="xref py py-func docutils literal notranslate"><span class="pre">solve_lin_sys()</span></code></a>.</p>
</dd>
</dl>
</div>
</dd></dl>

</section>
<section id="solve-lin-sys-component">
<h2>_solve_lin_sys_component<a class="headerlink" href="#solve-lin-sys-component" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.polys.solvers._solve_lin_sys_component">
<span class="sig-prename descclassname"><span class="pre">sympy.polys.solvers.</span></span><span class="sig-name descname"><span class="pre">_solve_lin_sys_component</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">eqs_coeffs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">eqs_rhs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">ring</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/polys/solvers.py#L360-L430"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.polys.solvers._solve_lin_sys_component" title="Permalink to this definition">¶</a></dt>
<dd><p>Solve a linear system from dict of PolynomialRing coefficients</p>
<p class="rubric">Explanation</p>
<p>This is an <strong>internal</strong> function used by <a class="reference internal" href="#sympy.polys.solvers.solve_lin_sys" title="sympy.polys.solvers.solve_lin_sys"><code class="xref py py-func docutils literal notranslate"><span class="pre">solve_lin_sys()</span></code></a> after the
equations have been preprocessed. After <a class="reference internal" href="#sympy.polys.solvers._solve_lin_sys" title="sympy.polys.solvers._solve_lin_sys"><code class="xref py py-func docutils literal notranslate"><span class="pre">_solve_lin_sys()</span></code></a> splits the
system into connected components this function is called for each
component. The system of equations is solved using Gauss-Jordan
elimination with division followed by back-substitution.</p>
<p class="rubric">Examples</p>
<p>Setup a system for <span class="math notranslate nohighlight">\(x-y=0\)</span> and <span class="math notranslate nohighlight">\(x+y=2\)</span> and solve:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">sring</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.polys.solvers</span> <span class="kn">import</span> <span class="n">_solve_lin_sys_component</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x, y&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">R</span><span class="p">,</span> <span class="p">(</span><span class="n">xr</span><span class="p">,</span> <span class="n">yr</span><span class="p">)</span> <span class="o">=</span> <span class="n">sring</span><span class="p">([</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">],</span> <span class="p">[</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eqs</span> <span class="o">=</span> <span class="p">[{</span><span class="n">xr</span><span class="p">:</span><span class="n">R</span><span class="o">.</span><span class="n">one</span><span class="p">,</span> <span class="n">yr</span><span class="p">:</span><span class="o">-</span><span class="n">R</span><span class="o">.</span><span class="n">one</span><span class="p">},</span> <span class="p">{</span><span class="n">xr</span><span class="p">:</span><span class="n">R</span><span class="o">.</span><span class="n">one</span><span class="p">,</span> <span class="n">yr</span><span class="p">:</span><span class="n">R</span><span class="o">.</span><span class="n">one</span><span class="p">}]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eqs_rhs</span> <span class="o">=</span> <span class="p">[</span><span class="n">R</span><span class="o">.</span><span class="n">zero</span><span class="p">,</span> <span class="o">-</span><span class="mi">2</span><span class="o">*</span><span class="n">R</span><span class="o">.</span><span class="n">one</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_solve_lin_sys_component</span><span class="p">(</span><span class="n">eqs</span><span class="p">,</span> <span class="n">eqs_rhs</span><span class="p">,</span> <span class="n">R</span><span class="p">)</span>
<span class="go">{y: 1, x: 1}</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="#sympy.polys.solvers.solve_lin_sys" title="sympy.polys.solvers.solve_lin_sys"><code class="xref py py-obj docutils literal notranslate"><span class="pre">solve_lin_sys</span></code></a></dt><dd><p>This function is used internally by <a class="reference internal" href="#sympy.polys.solvers.solve_lin_sys" title="sympy.polys.solvers.solve_lin_sys"><code class="xref py py-func docutils literal notranslate"><span class="pre">solve_lin_sys()</span></code></a>.</p>
</dd>
</dl>
</div>
</dd></dl>

</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h3><a href="../../index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Poly solvers</a><ul>
<li><a class="reference internal" href="#solve-lin-sys">solve_lin_sys</a></li>
<li><a class="reference internal" href="#eqs-to-matrix">eqs_to_matrix</a></li>
<li><a class="reference internal" href="#sympy-eqs-to-ring">sympy_eqs_to_ring</a></li>
<li><a class="reference internal" href="#id1">_solve_lin_sys</a></li>
<li><a class="reference internal" href="#solve-lin-sys-component">_solve_lin_sys_component</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="literature.html"
                        title="previous chapter">Literature</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="domainmatrix.html"
                        title="next chapter">Introducing the domainmatrix of the poly module</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/modules/polys/solvers.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="domainmatrix.html" title="Introducing the domainmatrix of the poly module"
             >next</a> |</li>
        <li class="right" >
          <a href="literature.html" title="Literature"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" >Polynomial Manipulation</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Poly solvers</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/polys/solvers.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:28:06 GMT -->
</html>